// -------------------------------------------------------------------------
// 		Copyright (C) 2018 - All Rights Reserved.
// -------------------------------------------------------------------------
//    	@FileName		:  	WFSingleton.h;
//    	@Author        	:  	webbleen@gmail.com;
//    	@Date         	:  	2018-07-13;
//    	@Desc			:	WFSingleton;
//
// -------------------------------------------------------------------------
#pragma once

#include <iostream>

template <class T>
class WFSingleton
{

public:

	WFSingleton()
	{
		//assert( !m_instance );
		m_pInstance = static_cast<T*>(this);
	}

	~WFSingleton()
	{
		//assert( m_instance );
		m_pInstance = NULL;
	}

public:

	static T* GetSingletonPtr()
	{
		if (NULL == m_pInstance)
		{
			m_pInstance = new T;
		}

		return m_pInstance;
	}

	static T& GetSingletonRef()
	{
		return *GetSingletonPtr();
	}

	static T* Instance()
	{
		return GetSingletonPtr();
	}

	static T& InstanceRef()
	{
		return GetSingletonRef();
	}

	static void ReleaseInstance()
	{
		delete m_pInstance;
		m_pInstance = NULL;
	}

private:
	static T* m_pInstance;
};

template <class T>
T* WFSingleton<T>::m_pInstance = NULL;


